Skip to content

fix(server): org profile page always shows "Register an agent" CTA when agents exist#4258

Draft
bokelley wants to merge 1 commit intomainfrom
claude/issue-4255-org-page-agent-count
Draft

fix(server): org profile page always shows "Register an agent" CTA when agents exist#4258
bokelley wants to merge 1 commit intomainfrom
claude/issue-4255-org-page-agent-count

Conversation

@bokelley
Copy link
Copy Markdown
Contributor

@bokelley bokelley commented May 8, 2026

Closes #4255

assembleOrgHealth in server/src/services/org-health.ts contained a stub that returned a hardcoded 0 for the agent count:

// Agent count — no org-scoped agents table yet; always 0 until one exists
Promise.resolve(0),

The agents table does exist — agents are stored as a JSONB array in member_profiles.agents (added in migration 014_agent_configs.sql). Because agentCount was always 0, suggestActions() always fired the "Register an agent to start integrating" CTA, regardless of how many agents the org had registered.

This PR replaces the stub with a query that counts all agents across the org's member profile:

SELECT COALESCE(SUM(COALESCE(jsonb_array_length(agents), 0)), 0) AS total
FROM member_profiles
WHERE workos_organization_id = $1

The double COALESCE handles: (inner) agents column being NULL on older rows; (outer) no matching profile row at all. Error path falls back to 0 (preserving the previous behavior on DB failure).

Visibility is intentionally not filtered — "has the org registered any agent" is the correct semantic for the CTA gate; a private agent is still a registered agent.

Non-breaking justification: server-side service change only; no schema, API, or protocol surface affected. Existing callers of assembleOrgHealth receive a more accurate suggested_actions array (the register_agent action is correctly absent when agents exist).

Pre-PR review:

  • code-reviewer: approved — SQL is safe (parameterized), double COALESCE is correct, error fallback consistent with surrounding pattern; nit: outer SUM redundant given one-per-org constraint (harmless)
  • internal-tools-strategist: approved — counting all visibility tiers is correct for this gate; display path for agents list is a separate read path, correctly out of scope

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout <num>
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See #3121
for context.

Session: https://claude.ai/code/session_01MGmeJKgbaF39WEmwEuDRQY


Generated by Claude Code

…f hardcoded 0

Resolves the "Register an agent" CTA appearing on the org profile page even
when agents are already registered. The agentCount in assembleOrgHealth was
stubbed as Promise.resolve(0) with a TODO comment; this replaces it with a
real query against member_profiles.agents (JSONB array, added in migration
014_agent_configs). The double COALESCE handles nullable agents columns on
older rows and the case where no profile row exists yet.
@bokelley bokelley added the claude-triaged Issue has been triaged by the Claude Code triage routine. Remove to re-triage. label May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-triaged Issue has been triaged by the Claude Code triage routine. Remove to re-triage.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Organization page shows "Register an agent" CTA even when agents are already registered

1 participant